package com.yunji.framework_template.web.mvc;

import java.sql.Timestamp;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.support.WebBindingInitializer;

import com.yunji.framework_template.web.mvc.editor.CustomTimestampEditor;
import com.yunji.framework_template.web.mvc.editor.HtmlFilterDoubleEditor;
import com.yunji.framework_template.web.mvc.editor.HtmlFilterIntegerEditor;
import com.yunji.framework_template.web.mvc.editor.HtmlFilterLongEditor;
import com.yunji.framework_template.web.mvc.editor.StringEditor;
import lombok.extern.slf4j.Slf4j;

/**
 * springMVC数据传参和输出绑定.
 * 
 * @author fenglb
 * @date 2014-3-20 下午5:36:10
 */
@Slf4j
@Configuration
public class BindingInitializer implements WebBindingInitializer {

    @InitBinder
    @Override
    public void initBinder(WebDataBinder binder) {
        log.info("WebDataBinder is initialing");
        binder.registerCustomEditor(Long.class, new HtmlFilterLongEditor());
        binder.registerCustomEditor(long.class, new HtmlFilterLongEditor());
        binder.registerCustomEditor(Integer.class, new HtmlFilterIntegerEditor());
        binder.registerCustomEditor(int.class, new HtmlFilterIntegerEditor());
        binder.registerCustomEditor(Double.class, new HtmlFilterDoubleEditor());
        binder.registerCustomEditor(double.class, new HtmlFilterDoubleEditor());
        binder.registerCustomEditor(String.class, new StringEditor());
        binder.registerCustomEditor(Timestamp.class, new CustomTimestampEditor("yyyy-MM-dd HH:mm:ss", true));
    }

}
